#!/bin/sh

# Load the privileged_startx daemon
/bin/launchctl unload -w /Library/LaunchDaemons/org.xquartz.privileged_startx.plist
/bin/launchctl load -w /Library/LaunchDaemons/org.xquartz.privileged_startx.plist

# Cache system fonts
/opt/X11/bin/font_cache --force --system

# Ensure ssh configs are setup
/opt/X11/libexec/privileged_startx

# Hook for the system X11 if it wants to do something after XQuartz installs
[[ -x /usr/X11/libexec/xquartz_postinst.sh ]] && /usr/X11/libexec/xquartz_postinst.sh

# Setup /usr/X11* symlinks
[[ -x /usr/libexec/x11-select ]] && /usr/libexec/x11-select /opt/X11
[[ -e /usr/X11 ]] || ln -s /opt/X11 /usr/X11
[[ -e /usr/X11R6 ]] || ln -s /opt/X11 /usr/X11R6

exit 0
